<?php
class Content extends AppModel
{
	var $name = 'Content';
	
	//function getContentById($id)
	//{
	//	$this->recursive = -1;
	//	$content = $this->find('first', array(
	//		'fields' => array('title', 'body'),
	//		'conditions' => 'id = ' . $id
	//	));
	//	return $content['Content'];
	//}
	
	function getMenuitems()
	{
		$this->recursive = 0;
		$menuItems = $this->find('all', array(
			'order' => 'parent_id ASC, order',
			'fields' => array(
				'Content.id', 
				'Content.title', 
				'Content.parent_id', 
				'Content.order',
				'Content.slug'
			),
			"conditions" => array("active = 1", "deleted = 0")
		));
		$menuData = array();
		foreach($menuItems As $key => $menuitem)
		{
			$menuData['items'][$menuitem['Content']['id']] = $menuitem;
			$menuData['parents'][$menuitem['Content']['parent_id']][] = $menuitem['Content']['id'];
		}
		if (isset($this->params['requested'])) {
			return $menuData;
		}
		return $menuData;
	}

    function getContent($url)
    {
        //get page contents
		$url = ($url == "/") ? "" : $url;
        $contentRes = $this->find('first', array(
			'fields' => array('Content.id', 'Content.title', 'Content.body', 'Content.slug'),
			'conditions' => array("Content.slug = '{$url}'", "deleted = 0", "active = 1")
		));

        if(!$contentRes) {
			$contentRes['Content']['title'] = 'Pagina niet gevonden';
			$contentRes['Content']['body'] = '<h1>Pagina niet gevonden</h1>';
            return $contentRes;
		}
		else {
            return $contentRes;
		}
    }
}
?>